package servletAction;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import util.DomainUtils;
import util.FormArgumentsException;
import actionForm.AddToContactGroupValidationForm;
import actionForm.DisconnectValidationForm;

public class DisconnectAction extends Action{
	

	public ActionForward execute(final ActionMapping pMapping,
			ActionForm pForm, final HttpServletRequest pRequest,
			final HttpServletResponse pResponse) {

		HttpSession session = pRequest.getSession(false);
		
		try {
			session.setAttribute(DomainUtils.CURRENT_USER_STRING, null);
			session.invalidate();
		}
		catch(Exception e) {
			if((e instanceof FormArgumentsException) == false) {
				pRequest.setAttribute(DomainUtils.ALERT_ERROR_STRING, "An error occur on the server.");
			}
			
			DomainUtils.keepParametersContent(pRequest);
		}
		

		return pMapping.findForward("home");
		
	}

}
